<?php
/*
# ------------------------------------------------------------------------
# JA Halite - Version 1.0 - Licence Owner JA180572
# ------------------------------------------------------------------------
# Copyright (C) 2004-2009 J.O.O.M Solutions Co., Ltd. All Rights Reserved.
# @license - Copyrighted Commercial Software
# Author: J.O.O.M Solutions Co., Ltd
# Websites:  http://www.joomlart.com -  http://www.joomlancers.com
# This file may not be redistributed in whole or significant part.
# ------------------------------------------------------------------------
*/ 
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
/**
 * IJAUserSetting class
 */
class IJAUserSetting extends JObject{
	/**
	 * @var cookieName
	 *
	 * @access public.
	 */
	var $cookieName = 'userseting';
	
	/**
	 * method factory: processing ajax request
	 * 
	 * @param string $action.
	 * @param stdClass $moduleObj is Data Module Object.
	 * @param plgSystemJa_usersetting $pluginObj using for refer current plugin object.
	 */
	function process( $action, $module, $plugin ){
	
		if( $action != '' ){
			switch( $action ){
				case 'loadform' : 
					$this->renderFormUserSetting( $module, $plugin );
					break;		
			}
		}
	}
	
	/**
	 * render form user setting.
	 *
	 * @param stdClass $module 
	 */
	function renderFormUserSetting( $module, $plugin ){	
		$params = new JParameter ($module->params);
		$path = JModuleHelper::getLayoutPath($module->module, 'usersetting_form');
		if ( file_exists($path) ) {
			include($path);
		}
	}	
		
	/**
	 * process on prepare binding html
	 *
	 * @param strign $configString 
	 * @param Strean $body that is HTML page.
	 * @param array $params parameters from configuration string.
	 * @param plgSystemJa_usersetting using for refer current plugin object.
	 */
	function onPrepareBindingHTML( $configString, $body, $params, $plugin ){
		$string = '';
		//thanhnv 090903
		//assign id for setting button
		$group = isset ($params['group'])?$params['group']:'';
		$sid = ($group) ? $params['modid'] . '-'.$group : $params['modid'];
		
		$id = 'ja-usersetting-item-'.$sid;
		$setting_id = 'ja-usersetting-loadform-'.$sid;
		
		
		
		$link = JURI::base().'index.php?do=ajax_usersetting&amp;modid='.$params['modid'].'&amp;group='.$group;
		$divIDReload = isset($params['idReload']) ? $params['idReload'] : '';
		$string =  '<div style="overflow:hidden" id="'.$id .'" class="'. (isset($params['class']) ? $params['class'] : 'ja-usersetting') .'">';
		$string .= '<a id="'.$setting_id.'" onclick="return jaUserSetting.showForm( this, $(\''.$id .'\'), \''.$divIDReload.'\')" href="'.$link.'" class="ja-usersetting-loadform">
						<span>Setting</span>
					</a>';
		$string .= '</div>';	
		return str_replace($configString, $string,  $body);
	}
}
?>